using RxjhServer.Network;
using System;

namespace RxjhServer
{
	public class 抓宠Class : IDisposable
	{
		public Players Playe;

		private float _FLD_FACE1;

		private float _FLD_FACE2;

		private int _IsNpc;

		private string _Name;

		private int _FLD_INDEX;

		private int _FLD_PID;

		private double _FLD_AT;

		private float _Rxjh_X;

		private float _Rxjh_Y;

		private float _Rxjh_Z;

		private float _Rxjh_cs_X;

		private float _Rxjh_cs_Y;

		private float _Rxjh_cs_Z;

		private int _Rxjh_Map;

		private int _Rxjh_Exp;

		private int _Max_Rxjh_HP;

		private int _Rxjh_HP;

		public float FLD_FACE1
		{
			get
			{
				return _FLD_FACE1;
			}
			set
			{
				_FLD_FACE1 = value;
			}
		}

		public float FLD_FACE2
		{
			get
			{
				return _FLD_FACE2;
			}
			set
			{
				_FLD_FACE2 = value;
			}
		}

		public int IsNpc
		{
			get
			{
				return _IsNpc;
			}
			set
			{
				_IsNpc = value;
			}
		}

		public string Name
		{
			get
			{
				return _Name;
			}
			set
			{
				_Name = value;
			}
		}

		public int FLD_INDEX
		{
			get
			{
				return _FLD_INDEX;
			}
			set
			{
				_FLD_INDEX = value;
			}
		}

		public int FLD_PID
		{
			get
			{
				return _FLD_PID;
			}
			set
			{
				_FLD_PID = value;
			}
		}

		public double FLD_AT
		{
			get
			{
				return _FLD_AT;
			}
			set
			{
				_FLD_AT = value;
			}
		}

		public float Rxjh_X
		{
			get
			{
				return _Rxjh_X;
			}
			set
			{
				_Rxjh_X = value;
			}
		}

		public float Rxjh_Y
		{
			get
			{
				return _Rxjh_Y;
			}
			set
			{
				_Rxjh_Y = value;
			}
		}

		public float Rxjh_Z
		{
			get
			{
				return _Rxjh_Z;
			}
			set
			{
				_Rxjh_Z = value;
			}
		}

		public float Rxjh_cs_X
		{
			get
			{
				return _Rxjh_cs_X;
			}
			set
			{
				_Rxjh_cs_X = value;
			}
		}

		public float Rxjh_cs_Y
		{
			get
			{
				return _Rxjh_cs_Y;
			}
			set
			{
				_Rxjh_cs_Y = value;
			}
		}

		public float Rxjh_cs_Z
		{
			get
			{
				return _Rxjh_cs_Z;
			}
			set
			{
				_Rxjh_cs_Z = value;
			}
		}

		public int Rxjh_Map
		{
			get
			{
				return _Rxjh_Map;
			}
			set
			{
				_Rxjh_Map = value;
			}
		}

		public int Rxjh_Exp
		{
			get
			{
				return _Rxjh_Exp;
			}
			set
			{
				_Rxjh_Exp = value;
			}
		}

		public int Max_Rxjh_HP
		{
			get
			{
				return _Max_Rxjh_HP;
			}
			set
			{
				_Max_Rxjh_HP = value;
			}
		}

		public int Rxjh_HP
		{
			get
			{
				return _Rxjh_HP;
			}
			set
			{
				_Rxjh_HP = value;
			}
		}

		public 抓宠Class()
		{
		}

		public 抓宠Class(Players Play, int pid)
		{
			Playe = Play;
			FLD_INDEX = Play.人物全服ID + 30000;
			Max_Rxjh_HP = 0;
			Rxjh_HP = 0;
			Rxjh_Map = Play.人物坐标_地图;
			Rxjh_X = Play.人物坐标_X;
			Rxjh_Y = Play.人物坐标_Y;
			Rxjh_Z = Play.人物坐标_Z;
			FLD_FACE1 = 0f;
			FLD_FACE2 = 0f;
			FLD_PID = pid;
		}

		public void Dispose()
		{
			if (World.jlMsg == 1)
			{
				Form1.WriteLine(1, "NpcClass_Dispose");
			}
			try
			{
				Playe = null;
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "NPC 关闭数据Dispose() 出错：" + ex?.ToString());
			}
		}

		~抓宠Class()
		{
		}

		public bool 查找范围玩家(int far_, Players Play)
		{
			try
			{
				if (Play.人物坐标_地图 != Rxjh_Map)
				{
					return false;
				}
				if (Playe.人物坐标_地图 == 7101)
				{
					far_ = 1000;
				}
				float num = Playe.人物坐标_X - Rxjh_X;
				float num2 = Playe.人物坐标_Y - Rxjh_Y;
				float num3 = (int)Math.Sqrt(num * num + num2 * num2);
				if (num3 <= (float)far_)
				{
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		public void 获取范围玩家发送增加数据包(int 更新)
		{
			if (World.jlMsg == 1)
			{
				Form1.WriteLine(1, "NpcClass_获取范围玩家发送增加数据包");
			}
			Rxjh_Map = Playe.人物坐标_地图;
			try
			{
				删除抓宠数据(Playe);
				if (更新 == 1)
				{
					更新抓宠数据(Playe);
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "获取范围玩家发送地面增加Npc数据包 出错：" + ex?.ToString());
			}
		}

		public void 更新抓宠数据(Players Playe)
		{
			using (发包类 发包类 = new 发包类())
			{
				发包类.Write4(1);
				发包类.Write2(FLD_INDEX);
				发包类.Write2(FLD_INDEX);
				发包类.Write2(FLD_PID);
				发包类.Write4(1);
				发包类.Write4(0);
				发包类.Write4(0);
				发包类.Write(Rxjh_X);
				发包类.Write(Rxjh_Z);
				发包类.Write(Rxjh_Y);
				发包类.Write4(1082130432);
				发包类.Write(FLD_FACE1);
				发包类.Write(FLD_FACE2);
				发包类.Write(Rxjh_X);
				发包类.Write(Rxjh_Z);
				发包类.Write(Rxjh_Y);
				发包类.Write4(3);
				发包类.Write4(0);
				发包类.Write4(12);
				发包类.Write4(0);
				if (Playe.Client != null)
				{
					Playe.Client.SendPak(发包类, 26368, Playe.人物全服ID);
				}
			}
		}

		public void 删除抓宠数据(Players Playe)
		{
			using (发包类 发包类 = new 发包类())
			{
				发包类.Write4(1);
				发包类.Write2(FLD_INDEX);
				发包类.Write2(FLD_INDEX);
				发包类.Write2(FLD_PID);
				发包类.Write4(1);
				发包类.Write4(-1);
				发包类.Write4(-1);
				发包类.Write(Rxjh_X);
				发包类.Write(Rxjh_Z);
				发包类.Write(Rxjh_Y);
				发包类.Write4(1082130432);
				发包类.Write(FLD_FACE1);
				发包类.Write(FLD_FACE2);
				发包类.Write(Rxjh_X);
				发包类.Write(Rxjh_Z);
				发包类.Write(Rxjh_Y);
				发包类.Write4(0);
				发包类.Write4(0);
				发包类.Write4(12);
				发包类.Write4(0);
				if (Playe.Client != null)
				{
					Playe.Client.SendPak(发包类, 26624, Playe.人物全服ID);
				}
			}
		}

		private void 更新NPC死亡数据(Players Playe)
		{
			using (发包类 pak = new 发包类())
			{
				if (Playe.Client != null)
				{
					Playe.Client.SendPak(pak, 34816, FLD_INDEX);
				}
			}
		}

		public void 发送移动数据(float X, float Y, int sl, int 移动方式)
		{
			if (World.jlMsg == 1)
			{
				Form1.WriteLine(1, "NpcClass_发送移动数据");
			}
			try
			{
				using (发包类 发包类 = new 发包类())
				{
					Random random = new Random();
					int num = random.Next(0, 2);
					double num2 = random.NextDouble() * (double)sl;
					double num3 = random.NextDouble() * (double)sl;
					if (num == 0)
					{
						Rxjh_X = X + (float)num2;
						Rxjh_Y = Y + (float)num3;
					}
					else
					{
						Rxjh_X = X - (float)num2;
						Rxjh_Y = Y - (float)num3;
					}
					发包类.Write(Rxjh_X);
					发包类.Write(Rxjh_Y);
					发包类.Write(Rxjh_Z);
					发包类.Write4(-1);
					发包类.Write4(移动方式);
					发包类.Write((float)num2);
					发包类.Write4(Rxjh_HP);
					Playe.Client.SendPak(发包类, 29696, FLD_INDEX);
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "发送移动数据 出错" + FLD_PID.ToString() + "|" + Name + " " + ex.Message);
			}
		}
	}
}
